<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AdminLTE 2 | Dashboard</title> <#-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<#include "/resource/resource-lte-css.html">
</head>
<body class="hold-transition skin-blue sidebar-mini">
  <div class="wrapper">
    <!-- header -->
    <#include "/admin/common/header.html">
    <!-- aside -->
    <#include "/admin/common/aside.html">
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1><i class="fa fa-file"></i>内容 <small>管理</small></h1>
        <ol class="breadcrumb">
          <li><a href="#">
              <i class="fa fa-dashboard"></i> Home
            </a></li>
          <li class="active">Dashboard</li>
        </ol>
      </section>
      <!-- Main content -->
      <section class="content">
        <!-- Main row -->
        <div class="row">
          <section class="col-lg-12">
            <!-- quick email widget -->
            <div class="box box-info">
              <div class="box-header with-border">文章</div>
              <div class="box-body">
                <form id="mainForm" action="${ctx}${adminPath}/content/edit/${(editVo.id)!}" method="post">
                  <div class="modal-body">
                    <section class="content">
                      <div class="row">
                        <div class="col-lg-3">
                          <#if (sorts)?? && (sorts?size>0)>
                          <div class="form-group ">
                            <label for="name">二级分类</label>
                            <select class="form-control" name="sortId"> <#include "/macro/selectRecursion.html"> <@cata sorts 0 0/>
                            </select>
                          </div>
                          </#if>
                          <div class="form-group ">
                            <label for="title">
                              <span>标题</span>
                              <span class="text-danger">(*)</span>
                            </label>
                            <input type="text" name="title" class="form-control" id="title" placeholder="请输入标题" value="${(editVo.title)!}">
                            <span>
                              <#if editVo??> <@spring.bind "editVo.title" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                          </div>
                          <div class="form-group ">
                            <label for="keyword">关键词</label>
                            <input type="text" name="keyword" class="form-control" id="keyword" placeholder="多个关键词用,分割" value="${(editVo.keyword)!}">
                            <span>
                              <#if editVo??> <@spring.bind "editVo.keyword" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                          </div>
                          <div class="form-group ">
                            <label for="tags">标签</label>
                            <input type="text" name="tags" class="form-control " id="tags" placeholder="多个标签使用,分割" value="${(editVo.tags)!}">
                            <span>
                              <#if editVo??> <@spring.bind "editVo.tags" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                          </div>
                          <div class="form-group ">
                            <label for="author">作者</label>
                            <input type="text" name="author" class="form-control " id="author" placeholder="请输入作者" value="${(editVo.author)!}">
                            <span>
                              <#if editVo??> <@spring.bind "editVo.author" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                          </div>
                          <div class="form-group ">
                            <label for="source">来源</label>
                            <input type="text" name="source" class="form-control " id="source" placeholder="请输入来源" value="${(editVo.source)!}">
                            <span>
                              <#if editVo??> <@spring.bind "editVo.source" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                          </div>
                          <div class="form-group ">
                            <label for="relationIds">相关文章</label>
                            <input type="text" name="relationIds" class="form-control " id="relationIds" placeholder="请输入相关文章" value="${(editVo.relationIds)!}">
                            <span>
                              <#if editVo??> <@spring.bind "editVo.relationIds" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                          </div>
                          <#if recomends??>
                          <div class="form-group ">
                            <label for="recomendFlag">推荐方式</label>
                            <div class="checkbox">
                              <#list recomends as recomend>
                              <label>
                                <input type="checkbox" name="recomendIds" value="${(recomend.id)!}"<#if editVo.recomendIds?? && (editVo.recomendIds?size>0)> <#list editVo.recomendIds as rid> <#if rid == recomend.id>checked</#if> </#list>
                                </#if> >
                                <span>${(recomend.name)!}</span>
                              </label>
                              </#list>
                            </div>
                          </div>
                          </#if>
                        </div>
                        <div class="col-lg-9">
                          <div class="form-group ">
                            <label for="cover">封面</label>
                            <input type="hidden" name="cover" id="cover" value="${(editVo.cover)!}">
                            <span>
                              <#if editVo??> <@spring.bind "editVo.cover" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                            <input id="file" type="file" class="file" name="file">
                          </div>
                          <div class="form-group ">
                            <label for="summary">摘要</label>
                            <textarea name="summary" id="summary" class="form-control" placeholder="请输入摘要" rows="4">${(editVo.summary)!}</textarea>
                             <span>
                              <#if editVo??> <@spring.bind "editVo.summary" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                          </div>
                          <div class="form-group ">
                            <label for="txt">
                              <span>内容</span>
                              <span class="text-danger">(*)</span>
                            </label>
                            <textarea name="txt" id="txt" placeholder="请输入内容" rows="10" cols="80" style="height: 250px;">${(editVo.txt)!}</textarea>
                             <span>
                              <#if editVo??> <@spring.bind "editVo.txt" /><@spring.showErrors "<br />" "error"/> </#if>
                            </span>
                          </div>
                        </div>
                      </div>
                    </section>
                  </div>
                  <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">提交</button>
                  </div>
                </form>
              </div>
            </div>
          </section>
          <!-- /.Left col -->
        </div>
        <!-- /.row (main row) -->

      </section>
      <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <#include "/admin/common/footer.html">
  </div>
  <!-- ./wrapper -->
  <input type="hidden" id="categoryId">
</body>
<#include "/resource/resource-lte-js.html">
<script type="text/javascript">
    var coverURL = $('#cover').val();
    // 有封面, 得预览封面
    if (coverURL != null && coverURL != '') {
        $("#file").fileinput({
            uploadUrl : COMMON_PATH + '/upload/upload-ret-url',
            overwriteInitial : false,
            language : 'zh',
            allowedFileTypes : [ 'image' ],
            allowedFileExtensions : [ 'jpg', 'png', 'gif' ],
            maxFilesNum : 1,
            maxFileSize : 2000,
            initialPreview : [ // 预览图片的设置
            '<img src="'+coverURL+'" class="file-preview-image">' ]
        });
    }
    // 没封面, 不预览
    else {
        $("#file").fileinput({
            uploadUrl : COMMON_PATH + '/upload/upload-ret-url',
            overwriteInitial : false,
            language : 'zh',
            allowedFileTypes : [ 'image' ],
            allowedFileExtensions : [ 'jpg', 'png', 'gif' ],
            maxFilesNum : 1,
            maxFileSize : 2000
        });
    }

    $('#file').on('fileuploaded', function(event, data, previewId, index) {
        var response = data.response;
        if (response.success) {
            var url = response.data;
            // alert(url);
            $('#cover').val(url);
        }
    });

    $(function() {
        var ue = UE.getEditor('txt');

        // 添加文章时, 校验并提交
        $('#mainForm').submit(function() {
            UE.getEditor('txt').sync();
        }).validate({
            ignore : "",
            rules : {},
            messages : {},
            errorPlacement : function(label, element) {
                // alert(label);
                label.insertAfter(element.is("#txt") ? element.next() : element);
            }
        });
    });
</script>
</html>
